<template>
    <!-- 接诊 -->
    <div class="receive">
        <navBar :titleName="titleName"></navBar>
        <search @messageData="getData" style="margin-top: 48px;" placeText="輸入病人姓名"
                textInfo="查询" @submitFun="searchClick"></search>
        <tabbar :message="msg"></tabbar>
        <nut-tab>
            <nut-tab-panel class="recive-nut" tabTitle="待诊列表">
                <myrow v-for="(item,index) in list" :key="index" style="height: 30px;border-bottom: 1px solid #DDDFE6;padding-top: 6px;"
                       @click="myClickCol(item)">
                    <nut-col :span="5" style="text-align: left;">
                        <div class="flex-content">{{item.pname}}</div>
                    </nut-col>
                    <nut-col :span="8" style="color: #999999;text-align: right;">
                        <div class="flex-content flex-content-light">{{item.adviceDate | formatDate }}</div>
                    </nut-col>
                    <nut-col :span="11" style="color: #999999;text-align: right;">
                        <div class="flex-content">{{item.adviceDate | formatTime }}</div>
                    </nut-col>
                </myrow>
            </nut-tab-panel>
            <nut-tab-panel tabTitle="接诊列表">
                <myrow v-for="(item,index) in visitList" :key="index"
                       style="height: 30px;border-bottom: 1px solid #DDDFE6;padding-top: 6px;"
                       @click="myClickCol(item)">
                    <nut-col :span="5" style="text-align: left;">
                        <div class="flex-content">{{item.pname}}</div>
                    </nut-col>
                    <nut-col :span="8" style="color: #999999;text-align: right;">
                        <div class="flex-content flex-content-light">{{item.adviceDate | formatDate }}</div>
                    </nut-col>
                    <nut-col :span="11" style="color: #999999;text-align: right;">
                        <div class="flex-content">{{item.adviceDate | formatTime }}</div>
                    </nut-col>
                </myrow>
            </nut-tab-panel>
            <!--<nut-tab-panel tabTitle=""></nut-tab-panel>-->
            <!--<nut-tab-panel tabTitle=""></nut-tab-panel>-->
        </nut-tab>
    </div>
</template>

<script>
    /* eslint-disable no-console,no-undef */

    import navBar from '@/components/common/navBar.vue'
    import search from '@/components/common/search.vue'
    import tabbar from '@/components/common/tabbar.vue'
    import myrow from '@/components/common/my-row.vue'

    export default {
        name: "receive",
        components: {
            navBar,
            search,
            tabbar,
            myrow
        },
        data() {
            return {
                titleName: "接诊",
                list:[
                ],
                visitList: [],
                msg: 2
            }
        },
        filters: {
            formatDate: function (time) {
                if (time != null && time != "") {
                    let date = new Date(time);
                    return formatDate(date, "yyyy-MM-dd");
                } else {
                    return "";
                }
            },
            formatTime: function (time) {
                if (time != null && time != "") {
                    let date = new Date(time);
                    return formatDate(date, "hh:mm:ss");
                } else {
                    return "";
                }
            }
        },
        created() {
            this.getVisit();
            this.getDoctorVisited();
        },
        methods:{
            searchClick:function(){
                console.log("==========searchClick=========");
            },
            getDoctorVisited: function () {
                this.API.GET(this.ApiUrl.GET_VISITED_TODAY, {
                    params: {
                        doctorId: this.$store.state.doctor.doctorId
                    }
                }).then(({data}) => {
                    if (data.code === 1200) {
                        this.visitList = data.data;
                    }
                }).catch(err => {
                    console.log("getUserInfoByOpenid::err------", err);
                });
            },
            getData(val) {
                //TODO:后续获取搜索框的传递回来的值
                console.log("receive children's value : " + val);
                if (val === ""){
                    this.getVisit();
                    return;
                }
                this.API.GET(this.ApiUrl.GET_PRE_VISIT_PATIENT, {
                    params: {
                        pname: val,
                    }
                }).then(({data}) => {
                    console.log("病人列表------", data);
                    if (data.code === 1200) {
                        this.list = data.data;
                    }
                }).catch(err => {
                    console.log("getPatients::err------", err);
                });
            },
            getVisit(){
                this.API.GET(this.ApiUrl.GET_PRE_VISIT_TODAY, {
                    params: {
                        doctorId: this.$store.state.doctor.doctorId
                    }
                }).then(({data}) => {
                    console.log("预约列表------", data);
                    if (data.code === 1200) {
                        this.list = data.data;
                    }
                }).catch(err => {
                    console.log("getUserInfoByOpenid::err------", err);
                });
            },
            myClickCol: function (item) {
                /*if (this.$store.state.accept) {
                    console.log("---------destroy accept--------");
                    this.$store.state.accept.$destroy();
                    console.log("---------destroy accept--------");
                }*/
                this.$store.state.medicineList = [];
                this.$store.state.freeInfoList = [];
                this.$store.state.diagMain = null;
                this.$store.state.diagSecond = null;
                let _that = this;
                setTimeout(function () {
                    console.log("---------push accept--------");
                    _that.$router.push({
                        name: 'acceptInfo', params: item
                    });
                },50)
                /*this.$router.push({
                    name: 'acceptInfo', params: item
                });*/
            },
        }
    }
</script>
<style>

    .receive{
        background-color: #e6e6e6;
    }

    .recive-nut .nut-tab-title {
        border-bottom: 1px solid #EDEDED;
        width: 100%;
        display: -webkit-box;
        display: -webkit-flex;
        display: flex;
        height: 50px;
        line-height: 48px;
        box-sizing: border-box;
        position: relative;
        max-width: 34%;
    }

    .receive .nut-tab {
        padding: 10px 0 0 0;
        border:0;
    }

    .receive .nut-tab-active .nut-tab-link {
        font-size: 14px;
        font-weight: bold;
        border: 0;
        color: #007aff !important;
    }

    .receive .nut-tab-item{
        height: auto;
        min-height: 700px;
    }
</style>